//----------------------------------------------------------------------------
// M A R I T I M E  R E S E A R C H  I N S T I T U T E  N E T H E R L A N D S
//----------------------------------------------------------------------------
// Copyright (C) 2009 - MARIN - All rights reserved - http://www.marin.nl
//----------------------------------------------------------------------------
// Program    : mermaid
// Module     : vbm
// File       : FileUtils.cpp
//----------------------------------------------------------------------------

#include <sys/stat.h>

#include "FileUtils.h"


/// exchanges or adds specified extension
void FileUtils::changeExtension(std::string *str, const std::string& ext)
{
    unsigned dot = str->rfind(".");
    if (dot != std::string::npos)
    {
        *str = str->substr(0, dot);
    }
    *str += std::string(".") + ext;
}


/// checks if specified file exists
bool FileUtils::exists(const std::string& file)
{
    struct stat st;
    return stat(file.c_str(), &st) == 0;
}


